/* NOTICE
    OpenJaWS - Open Java Weather Station
    
    Copyright (C) 2008 Grant Gardner <grant@lastweekend.com.au>
    
    OpenJaWS is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
NOTICE */

package au.com.lastweekend.openjaws.units;

public enum PressureUnit implements Unit {

    PASCAL(1.0, "Pa"),
    YOTTAPASCAL(SIPrefix.YOTTA),
    ZETTAPASCAL(SIPrefix.ZETTA),
    EXAPASCAL(SIPrefix.EXA),
    PETAPASCAL(SIPrefix.PETA),
    TERAPASCAL(SIPrefix.TERA),
    GIGAPASCAL(SIPrefix.GIGA),
    MEGAPASCAL(SIPrefix.MEGA),
    KILOPASCAL(SIPrefix.KILO),
    HECTOPASCAL(SIPrefix.HECTO),
    DECAPASCAL(SIPrefix.DECA),
    DECIPASCAL(SIPrefix.DECI),
    CENTIPASCAL(SIPrefix.CENTI),
    MILLIPASCAL(SIPrefix.MILLI),
    MICROPASCAL(SIPrefix.MICRO),
    NANOPASCAL(SIPrefix.NANO),
    PICOPASCAL(SIPrefix.PICO),
    FEMTOPASCAL(SIPrefix.FEMTO),
    ATTOPASCAL(SIPrefix.ATTO),
    ZEPTOPASCAL(SIPrefix.ZEPTO),
    YOCTOPASCAL(SIPrefix.YOCTO),

    BAR(100 * KILOPASCAL.multiplier, "bar"),
    DECIBAR(0.1 * BAR.multiplier, "dbar"),
    MILLIBAR(0.001 * BAR.multiplier, "mbar"),

    // TODO: psi really should be determined by converting kgs to pounds and inches to metres.
    POUNDS_PER_SQUARE_INCH(6894.75729, "psi"),
    INCHES_OF_MERCURY(3386.0, "inHg"),
    ATMOSPHERE(101325, "atm"),
    TORR(ATMOSPHERE.multiplier / 760.0, "torr");

    private double multiplier;
    private String utfSymbol;

    private PressureUnit(double multiplier, String symbol) {

        this.multiplier = multiplier;
        this.utfSymbol = symbol;
    }

    private PressureUnit(SIPrefix metric) {

        this(metric.getMultiplier(), metric.toString() + "Pa");

    }

    public String toString() {

        return utfSymbol;
    }

    public double convertFrom(double value, Unit unit) {

        return value * ((PressureUnit) unit).multiplier / multiplier;

    }

    public double getMultiplier() {

        return multiplier;
    }

}
